package com.xiaolin.Thread;

/**
 * @ClassName TestThreadGroup
 * @Description TODO
 * @Detail 测试线程组，一个线程组可以包含线程和其他线程组
 * @Author MyPC
 * @Date 2020/9/26
 * @Version 1.0
 */
public class TestThreadGroup {
    public static void main(String[] args) {
        ThreadGroup threadGroup=new ThreadGroup("hello");
        MyRunnable m1=new MyRunnable();
        //可以给线程指定线程名，如果不指定则线程名自动生成
        Thread t1=new Thread(threadGroup,m1,"线程1");
        Thread t2=new Thread(threadGroup,m1,"线程2");
        t1.start();
        t2.start();;
    }
}

class MyRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println("所属线程组："+Thread.currentThread().getThreadGroup()+"线程名："+Thread.currentThread().getName());
        for (int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+"===="+i);
        }
    }
}
